﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ApplicantList.aspx.cs" Inherits="CRMWeb.Pages.Application.ApplicantList" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Applicant List</title>

</head>
<body>

    <div class="fitem">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" id="btnAdd" plain="true" onclick="openCombinDialog()">Add </a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-remove" id="btnRemove" style="display: none" plain="true" onclick="disCombineApplicant()">Remove </a>
    </div>

    <div>
        <table id="dgApplicant" class="easyui-datagrid" title="All Applicants" style="width: auto; height: 550px" remotesort="false"
            data-options="url: '/WebServices/ApplicationInfo.ashx?method=SelectAllApplicants&app_id=' + getQuerystring('app_id', 0) + '&ContactID=' + getQuerystring('contact_id', 0),
            onDblClickRow: function (index, rowdata) {
             window.location.href = '/Pages/Contact/ContactDetail.aspx?contact_id=' + rowdata.ContactID;
            },
            onSelect:function(){
            $('#btnRemove').show();
            }"
            autorowheight="true" rownumbers="true" fitcolumns="true" singleselect="true">
            <thead>
                <tr>
                    <th field="FirstName" width="35" sortable="true">First Name</th>
                    <th field="MiddleName" width="35" sortable="true">Middle Name</th>
                    <th field="SurName" width="35" sortable="true">Surname</th>
                    <th field="Mobile" width="30" sortable="true">Mobile</th>
                    <th field="Email" width="70" sortable="true">Email</th>
                    <th field="State" width="15" sortable="true">State</th>
                    <th field="DateBirth" width="30" sortable="true">BirthDate</th>
                    <th field="CreateDate" width="40" sortable="true">CreateDate</th>
                    <th field="ContactID" width="30" sortable="true">Client Profile</th>
                </tr>
            </thead>
        </table>
    </div>

    <div id="dlgRemoveApp" class="easyui-dialog" title="Confirm Discombine" style="width: 300px; height: 160px" closed="true" resizable="false" modal="true">
        <h4 style="text-align: center">Are you sure to remove combined Applicant ?</h4>
        <div class="fitem" style="text-align: center" id="spnButton">

            <a id="lnkconfirm" class="easyui-linkbutton l-btn" onclick="discombine()" href="javascript:void(0)" group="">
                <span class="l-btn-left">
                    <span class="l-btn-text">OK</span>
                </span>
            </a>
            <a id="lnkcancel" class="easyui-linkbutton l-btn" onclick="$('#dlgRemoveApp').dialog('close')" href="javascript:void(0)" group="">
                <span class="l-btn-left">
                    <span class="l-btn-text">Cancel</span>
                </span>
            </a>
        </div>

        <div id="spnanim" style="text-align: center">
            <img id="deleteProgressbar" style="margin-left: 20px" src="/Media/loading.gif" />
            <label id="lblcount" style="margin-left: 20px">5</label>
        </div>
    </div>
    <script type="text/javascript">

        function openCombinDialog() {
            var thm = getCookie('Theme');
            if (thm == 'null' || thm == '' || thm == null)
                thm = 'Default';
            popupWinCenter('/Pages/Application/ApplicationCombine.aspx?app_id=' + getQuerystring('app_id', '') + '&Theme=' + thm, 'Combine Application', 900, 250);
        }
        function popupWinCenter(URL, title, w, h) {
            var left = (screen.width / 2) - (w / 2);
            var top = (screen.height / 2) - (h / 2);
            var strfeatures = 'width=' + w + ', height= ' + h + ', top=' + top + ',left=' + left;
            var newWin = window.open(URL, title, strfeatures);
            newWin.onload = function () { window.focus(); }

        }
        function startTimer(limit) {
            setTimeout(function () {
                if (limit == 0) {
                    $('#spnanim').hide();
                    $('#spnButton').show();
                }
                else {
                    $('#lblcount').html(limit);
                    startTimer(limit - 1);
                }
            }, 500);
        }

        function disCombineApplicant() {
            var totalrows = $('#dgApplicant').datagrid('getRows');
            var len = totalrows.length;
            if (len == 1) {
                $.messager.alert('Morgan CRM', 'More than one Applicant required to Discombine');
                return;
            }
            else
                $('#dlgRemoveApp').dialog('open');
        }


        $('#dlgRemoveApp').dialog({
            onOpen: function () {
                $('#lblcount').html('');
                startTimer(5);
                $('#spnanim').show();
                $('#spnButton').hide();
            },
            onClose: function () {
                $('#spnanim').show();
                $('#spnButton').hide();
                $('#lblcount').html('');
            }
        });
        function discombine() {

            var row = $('#dgApplicant').datagrid('getSelected');
            var hOperator = $('#ContentPlaceHolder1_appProfile_hdnUserName').val();
            var c_appid = getQuerystring('app_id', '');
            var contactid = row.ContactID;

            $.ajax({
                url: '/WebServices/ApplicationInfo.ashx?method=discombineApplication',
                data: { currentAppID: c_appid, ContactID: contactid, combineAppID: '', Operator: hOperator },
                success: function (response) {
                    if (response == 'True') {
                        window.location.reload();
                    }
                    else if (response == '1') {
                        $.messager.alert('Morgan CRM', '<span style="color:red"> Application Discombine failed </span> ');
                        $('#dlgRemoveApp').dialog('close');
                    }
                },
                error: function () {
                    $.messager.alert('Morgan CRM', '<span style="color:red"> Application Discombine failed </span> ');
                }
            });
        }
    </script>
</body>

</html>
